package cn.wolfcode.crm.query;

import lombok.Getter;
import lombok.Setter;

import java.util.Collections;
import java.util.List;

/**
 * Created by Administrator on 2020/3/11.
 */

@Getter@Setter
public class PageResult<T> {
	private int currentPage;//用户传过来
	private int pageSize;//用户传过来
	private int totalCount;//查询出来
	private List<T> list;//查询出来
	private int totalPage;//计算出来
	private int prevPage;//计算出来
	private int nextPage;//计算出来

	//当总条数为0时使用 new PageResult(3)
	public PageResult(Integer pageSize){
		this(1,0, Collections.EMPTY_LIST,pageSize);
	}

	public PageResult(int currentPage,int totalCount ,List<T> list ,int pageSize ){
		this.currentPage =currentPage;
		this.pageSize =pageSize;
		this.totalCount = totalCount;
		this.list = list;

		//页面显示数大于总条数时
		if(totalCount <= pageSize){
			this.totalPage = 1;
			this.prevPage = 1;
			this.nextPage = 1;
			return;
		}

		this.totalPage = this.totalCount % this.pageSize == 0 ? this.totalCount / this.pageSize :this.totalCount / this.pageSize + 1;
		this.prevPage = this.currentPage - 1 >= 1 ? this.currentPage -1 : 1;
		this.nextPage = this.currentPage + 1 <= this.totalPage ? this.currentPage +1 : this.totalPage;
	}

}
